package cn.wsalix.admin.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.anlaser.repository.CommonRepository;
import cn.wsalix.admin.entity.MenuPermit;
import cn.wsalix.admin.entity.RolePermit;

/**
 * @author jskyme
 * 
 */
public interface RolePermitRepository extends CommonRepository<RolePermit> {

	@Query("select rm.menuPermit from SysUser u,UserRole ur,RolePermit rm,MenuPermit mp where u.id = :userId and u.id=ur.user.id and ur.role.id= rm.role.id and mp.id=rm.menuPermit.id")
	List<MenuPermit> findPermsByUserId(@Param("userId") Long userId);

	@Query("select rm.menuPermit from RolePermit rm,MenuPermit mp where rm.role.id = :roleId and mp.id=rm.menuPermit.id")
	List<MenuPermit> findPermsByRoleId(@Param("roleId") Long roleId);

}
